package edu.snake.implement.model.character.state;

import edu.snake.core.model.character.Character;
import edu.snake.core.model.character.CharacterState;
import edu.snake.core.model.character.StateCharacter;
import edu.snake.implement.model.character.iterator.CompositeIterator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class CharacterStateWithElement implements StateCharacter {

    private final Character character;
    private final List<Character> characterElements;
    private final CharacterState state = CharacterState.WITH_ELEMENT;

    public CharacterStateWithElement(Character character) {
        this.character = character;
        this.characterElements = new ArrayList<Character>();
    }

    @Override
    public CharacterState getState() {
        return state;
    }

    @Override
    public void add(Character character) {
        characterElements.add(character);
    }

    @Override
    public void remove(Character character) {
        characterElements.remove(character);
    }

    @Override
    public Character getChild(int i) {
        return characterElements.get(i);
    }

    @Override
    public Iterator<Character> iterator() {
        return new CompositeIterator(characterElements.iterator());
    }

    @Override
    public int size() {
        int size = 1;
        for (Character characterElement : characterElements) {
            size++;
        }
        return size;
    }

    @Override
    public String toString() {
        return "CharacterStateWithElement{" +
                "character=" + character +
                ", state=" + state +
                '}';
    }
}
